<template>
  <div style="margin-top: 60px;margin-left:330px;width: 300px;height: 500px;border: 0px solid red;">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <!-- 时间点输入框 -->
      <el-form-item label="时间点" prop="datePoint">
        <el-input v-model="ruleForm.datePoint"></el-input>
      </el-form-item>
      <!-- 标题输入框 -->
      <el-form-item label="标题" prop="title">
        <el-input v-model="ruleForm.title"></el-input>
      </el-form-item>
      <!-- 内容输入框 -->
      <el-form-item label="内容" prop="content">
        <el-input v-model="ruleForm.content"></el-input>
      </el-form-item>
      <!-- 提交按钮和重置按钮 -->
      <el-form-item>
        <el-button type="success" @click="submitForm('ruleForm')">立即创建</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      category: null,
      imageUrl: '',
      ruleForm: {
        datePoint: '',
        title: '',
        content: '',
        genealogyId: 0
      },
      dormitoryList: '',
      rules: {
        datePoint: [
          { required: true, message: '请输入时间点', trigger: 'blur' }
        ],
        title: [
          { required: true, message: '请输入标题', trigger: 'blur' }
        ],
        content: [
          { required: true, message: '请输入内容', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    // 提交表单
    submitForm(formName) {
      const _this = this;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$http.post('http://localhost:8081/event/save', _this.ruleForm).then(function (resp) {
            if (resp.data.code == 0) {
              _this.$alert('添加成功', '', {
                cancelButtonText: '确定',
                callback: () => {
                  _this.$router.push('/eventManager?id=' + _this.$route.query.genealogyId);
                }
              });
            }
          });
        }
      });
    },
    // 重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
  created() {
    // 将路由中的genealogyId赋值给ruleForm的genealogyId属性
    this.ruleForm.genealogyId = this.$route.query.genealogyId;
  }
}
</script>

<style>

</style>